package com.itheima.tlais_web_management.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

//过滤器
//过滤器拦截所有资源 — — — — tomcat 提供的
//通过 DispatcherServlet：前端控制器 （ 因为 tomcat 不识别 controller 识别 service 程序）tomcat是servlet容器
@WebFilter("/*")
public class Demofilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init 初始化方法执行了");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("拦截到一次请求,之前");
        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println("拦截到一次请求,之后");

    }

    @Override
    public void destroy() {
        System.out.println("destroy 销毁方法执行了");
    }
}
